#ifndef _MARIO_H_
#define _MARIO_H_

#include "Sprite.h"
#include "Object.h"

#include "Collision.h"
#include "DxInput.h"
#include "Score.h"

//#include "MarioManager.h"

#include <list>
using namespace std;

#define MARIO_VX		0.4
#define MARIO_VX_MAX	0.5
#define MARIO_VY		2.0
#define GRAVITY			0.01
#define ACCEL_X			0.001
#define BOTTOM			590





class MarioManager;
/**--------------------------------------------------------
*Program/Project : GameMario
*Written by : 
*Email :
*Created date : 7/10/2012
*Modified by :
*Modified date :
*Version : 1.0
*Description : Lop khoi tao Mario
--------------------------------------------------------**/
class Mario: public Object
{
protected:
	/*Sprite* _sprRight;
	Sprite* _sprLeft;
	Sprite* _sprJumpLeft;
	Sprite* _sprJumpRight;

	Sprite* _curSprite;*/
	Sprite* _spriteSmall;		//Sprite mario lon
	Sprite* _spriteBig;			//Sprite mario lon
	Sprite* _spriteBullet;		//Sprite mario co bullet
	Sprite* _spriteLight;		//Sprite tao nhap nhay

	//0: Left | 1: Right
	bool _turnLeft;				//kiem tra huong di mario
	bool _isJumping;			//kiem tra trang thai nhay
	bool _isAi;					//quai tu dong
	bool _isSmall;				//kiem tra mario con nho hay lon?
	bool _isShoot;				//kiem tra mario duoc ban bullet hay chua
	bool _isHasStar;			//kiem tra mario co an sao hay chua?
	bool _isMoveDown;			//Kiem tra mario co the chuoi cong

	float _vx;
	float _vy;
	float _accelX;				//gia toc x
	float _accelY;				//gia toc y
	float _xOld;				//toa do x cu
	float _yOld;				//toa do y cu

	float _xPosOld;				//toa do x cu, khi chui vao cong
	float _yPosOld;				//toa do y cu, khi chui cong ra

	RECT _rectHead;
	RECT _rectOld;


	float timeBullet;				//khoang thoi gian sau 1 lan ban bullet
	float timeTransferState;		//khoang thoi gian chuyen frame
	int countFrame;					//so frame chuyen
	float timeProtect;				//thoi gian bao ve sau khi chet

	LPDIRECT3DDEVICE9 d3ddv;
	LPDIRECT3DSURFACE9 BackBuffer;
	LPD3DXSPRITE SpriteHandler;

public:
	//RECT _rectBond;
	list<Object*> *collisionObjectList;

	MarioManager* game_Mario;
	D3DXVECTOR2 GetPosition();		//lay vi tri mario cho viec update theo camera
	int mario_State;				//trang thai cua mario

	Mario(LPDIRECT3DDEVICE9 d3ddv,  LPDIRECT3DSURFACE9 BackBuffer, LPD3DXSPRITE SpriteHandler, float x, float y, MarioManager* Game_Mario, int Object_State, int Direction);
	~Mario(void);

	//void Update(int _ScreenWidth, int _ScreenHeight, int time, list<Object*> *ObjectList, DxInput *input);
	void Update(list<Object*>* staObjs, list<Object*>* dynObjs, DxInput* input, float time);
	void Move(list<Object*>* staObjs, list<Object*>* dynObjs, float time);
	void CollisionOnTop(Object* obj,list<Object*>* staObjs,list<Object*>* dynObjs);
	void UpdateNormal(list<Object*>* staObjs, list<Object*>* dynObjs, DxInput* input, float time);

	void ProcessInput(DxInput *input);
	void Reset();
	void ResetJump();
	void TurnLeft();
	void TurnRight();
	void Jump();

	void Render();
	void ChangeSprite(Sprite* sprite);
	void ResetRect();
	OBJECT_TYPE GetTypeObject(){return OBJECT_MARIO;}
	void ChangeState(int state);
};

#endif
